package com.zhonglz.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhonglz.commons.base.BaseController;
import com.zhonglz.model.BuCertInfo;
import com.zhonglz.model.BuSignInfo;
import com.zhonglz.util.result.ResultUtils;
import com.zhonglz.util.tools.DataGrid;
import com.zhonglz.util.tools.ObjectUtils;


/***
 * 签署信息
 * @author zhonglz
 *
 */
@Controller
@RequestMapping("/sys/signInfo")
public class BuSignInfoController extends BaseController {

	private static Logger logger = LoggerFactory.getLogger(BuSignInfoController.class);
	
	/****
	 * 分页查询证书信息
	 * @param startTime
	 * @param endTime
	 * @param pageNumber
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ResponseBody
    @RequestMapping("selectListByData")
    public DataGrid selectListByData(BuSignInfo bBuSignInfo,
    		@RequestParam(defaultValue="") String startTime,
    		@RequestParam(defaultValue="") String endTime,
    		@RequestParam(defaultValue = "1") int pageNumber,
			@RequestParam(defaultValue = "10") int pageSize,
			HttpServletRequest req) {
    	DataGrid dataGrid = null;
		// 封装查询条件参数
		Map<String, Object> mapParam = new HashMap<String, Object>();
		if(ObjectUtils.isNotEmpty(startTime)){
			startTime+=" 00:00:00";
			mapParam.put("startTime",startTime);
		}
		if(ObjectUtils.isNotEmpty(endTime)){
			endTime+=" 23:59:59";
			mapParam.put("endTime",endTime);
		}
		
		PageHelper.startPage(pageNumber, pageSize);
		List<BuSignInfo> selectInfoList=buSignInfoService.selectByList(mapParam);
		PageInfo<BuSignInfo> info = new PageInfo<BuSignInfo>(selectInfoList);
		// 封装结果集
		dataGrid = new DataGrid(info.getTotal(),selectInfoList,info.getPages(),info.getPageNum(),ResultUtils.CODE_SUCCESS);
    	return dataGrid; 
	}
	
	@ResponseBody
    @RequestMapping("selectInfoById")
	public BuSignInfo selectInfoById(String id) {
		return buSignInfoService.selectInfoById(id);
	}
	
	/***
	 * 保存信息
	 * @return
	 */
	@ResponseBody
    @RequestMapping("saveInfo")
	public ResultUtils saveInfo(BuSignInfo buSignInfo) {
		return buSignInfoService.saveInfo(buSignInfo);
	}
	
	
}
